package entility;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Range  implements Serializable, Comparable<Range> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	public int min;
	public int max;
	
	public List<Integer> values;
	
	public int size;

	public Boolean minInf;
	public Boolean maxInf;
	
	public Range(int min, int max)
	{
		this.min = min;
		this.max = max;
		this.size = 0;
		
		this.values = new LinkedList<Integer>();
	}
	
	
	
	public Range (String min, String max)
	{
		if(min .equals("?") )
		{
			minInf = true;
		}
		else
		{
			this.min = new Integer(min);
		}
		
		if(max .equals("?") )
		{
			maxInf = true;
		}
		else
		{
			this.max = new Integer(max);
		}
		
		
		
	}
	


	@Override
	public String toString() {
		return "Range [min=" + min + ", max=" + max
				+ ", size=" + size + "]";
	}



	public Range(String url) {

		String data[] = url.split(":");
		this.min = new Integer(data[0]);
		this.max = new Integer(data[1]);
		

	}

	public boolean contains(Integer value) {

		if(value > min && value <= max )
			return true;
		return false;
	}


	public void inc()
	{
		size++;
	}

	public void inc(int value)
	{
		size++;
		values.add(value);
	}
	
	public int getSize()
	{
		return this.size;
	}
	
	

	@Override
	public int compareTo(Range arg) {
		
		if(this.getSize() < arg.getSize())
			return 1;
		else if(this.getSize() > arg.getSize())
			return -1;
			else
		return 0;
	}

	
	public List<Integer> getValue()
	{
		return this.values;
	}
	
}
